﻿<!DOCTYPE html>

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<link href="/LiberUI/Style/LiberUI.css" rel="stylesheet" />
<link href="/SiteUI/Base.css" rel="stylesheet" />
<link href="/SiteUI/Register/Register.css" rel="stylesheet" />
<title>天联云-账号绑定</title>
<html>

<body>
    <div class="view" id="headBar">
        <div class="row">
            <div class="col-lg-5 col-lg-offset-1" id="siteLogo">

            </div>
            <div class="col-lg-6" id="siteLink">
                <a href="/Index.html">首页</a>
                <a href="/Products.html">采购云协同</a>
                <a href="/BizCase.html">案例</a>
                <a href="/AboutUS.html">关于我们</a>
            </div>
        </div>
    </div>

    <div class="view_fix" id="viewBindAcnt">
        <div class="row">
            <div class="col-lg-6">
                <div class="row">
                    <div class="col-lg-12">
                        <img id="userInfo_headImg" src="/SiteUI/Imgs/acntOk.png" />
                    </div>
                    <div class="col-lg-12" id="userInfoTxt">
                        <h3 id="userInfo_name">用户名</h3>
                        <h4 id="userInfo_tip">欢迎加入天联云</h4>
                        <h6 id="userInfo_prompt">请登录平台账号完成绑定，如果没有平台账号，请<a class="LinkTo" href="/Register.html">注册新账号</a></h6>
                    </div>
                </div>                
            </div>
            <div class="col-lg-6" id="vr-login">
                <div class="row">
                    <div class="col-lg-8">
                        <h5>账号：</h5>
                        <input maxlength="11" id="txbAcnt" placeholder="手机号/邮箱" />
                    </div>
                    <div class="col-lg-4">
                        <h5>&nbsp;</h5>
                        <div class="inputTip" id="it-acnt"></div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-lg-8">
                        <h5>登录密码：</h5>
                        <input maxlength="30" id="txbPassword" type="password" placeholder="您的登录密码" />
                    </div>
                    <div class="col-lg-4">
                        <h5>&nbsp;</h5>
                        <div class="inputTip" id="it-pwd"></div>
                    </div>
                    <div class="col-lg-8 button btn-big" id="btnBindAcnt">
                        登录并绑定
                    </div>
                </div>
            </div>
        </div>

    </div>
    <div class="view" id="pageFoot">

    </div>
    <script src="LiberUI/Scripts/jquery.js"></script>
    <script src="LiberUI/Scripts/LiberUI.Base.js"></script>
    <script src="LiberUI/Scripts/LiberUI.js"></script>
    <script src="LiberUI/Scripts/LiberUI.Action.js"></script>
    <script src="SiteUI/res_sobiz.js"></script>
    <script>
        var BindAcnt = {
            Acnt: {
                acnt: null,
                pass: null,
                openid: null,
                opensrc: null,
                openheadimg: null,
                openname:null
            },
            checkPwd: function () {
                var p = $("#txbPassword");
                if (p.val().length >= 6 && p.vl().indexOf(" ") == -1) {
                    $("#it-pwd").vl("").removeClass("error,info,success");
                    return true;
                } else {
                    $("#it-pwd").vl("密码长度至少为6位");
                    return false;
                }
            },
            checkAcnt:function(){
                var a = $("#txbAcnt").vl();
                if (a.length == 0) {
                    $("#it-acnt").vl("账号不能为空");
                    return false;
                }
                else {
                    $("#it-acnt").vl("");
                    return true;
                }
            },
            getWxUserInfoEnd: function (rtn) {
                if (rtn.IsPositive == false) {
                    setTimeout(function () { $.getJSON("/TLB2B/GetUserInfo", {}, BindAcnt.getWxUserInfoEnd); }, 500);
                }
                else {
                    $("#viewOpenUser").fadeIn();
                    var uinfo = JSON.parse(JSON.parse(rtn.Data));
                    BindAcnt.Acnt.openheadimg = uinfo.headimgurl;
                    BindAcnt.Acnt.openid = uinfo.openid;
                    BindAcnt.Acnt.openname = uinfo.nickname;

                    $("#userInfo_headImg").attr("src", BindAcnt.Acnt.openheadimg);
                    $("#userInfo_name").vl(BindAcnt.Acnt.openname);
                    $("#userInfo_tip").vl("欢迎，您已使用微信帐号登录");
                }
            },
            btnBind:null,
            loginBind: function () {
                if (BindAcnt.checkAcnt() & BindAcnt.checkPwd()) {
                    BindAcnt.btnBind.disable().vl("正在登录...");
                    BindAcnt.Acnt.acnt = $("#txbAcnt").vl();
                    BindAcnt.Acnt.pass = $("#txbPassword").vl();
                    $.post("/Register/BindOpenAcnt", BindAcnt.Acnt, BindAcnt.bindAcntEnd);
                }
            },
            bindAcntEnd: function (rtn) {
                if (rtn.IsPositive) {
                    //提示绑定成功，跳转
                    success( "现在您可以使用微信账号直接登录本平台", 5, function () {
                        $.post("/SoBiz/Login", { 'opensrc': BindAcnt.Acnt.opensrc }, function (rtn) {
                            if (rtn.IsPositive) {
                                window.location = "/SoBiz/LoginEnd";
                            }
                        });
                    });
                }
                else {
                    //TODO:显示错误信息
                    error("抱歉，未能绑定平台账号，错误如下：" + ErrFormate(res_sobiz, rtn.ErrorSrc, rtn.ErrorCode, rtn.Error));
                    BindAcnt.btnBind.enable().vl("登录并绑定");
                }
            }
        }

        $(function () {
            //元素失去焦点触发
            $("#txbPassword").blur(BindAcnt.checkPwd);
            $("#txbAcnt").blur(BindAcnt.checkAcnt);
            //判断是否为通过第三方账号登录
            var frm = getUrlParam("from");
            if (frm != null) {
                switch (frm) {
                    case "wechat":
                        //加载微信用户信息
                        BindAcnt.Acnt.opensrc = frm;
                        $.getJSON("/TLB2B/GetUserInfo", {}, BindAcnt.getWxUserInfoEnd);
                        break;
                }
            }
            BindAcnt.btnBind = new LiberUI.Button("#btnBindAcnt")
                                          .on("LCclick", BindAcnt.loginBind);

            $("#pageFoot").load("/common/pageFoot.html");

            $("#txbAcnt").focus();
        })
    </script>


    <div id="tplPrompt" style="display:none">
        <div class="prompt_success">
            <div class="p_body">
                <h4>title</h4>
                <span>message</span>
            </div>
        </div>
        <div class="prompt_info">
            <div class="p_body">
                <h4>title</h4>
                <span>message</span>
            </div>
        </div>
        <div class="prompt_err">
            <div class="p_body">
                <h4>title</h4>
                <span>message</span>
            </div>
        </div>
    </div>

    <script>
    window.success = function (msg, delay, fnCallback) {
        var cnt = $("#tplPrompt>.prompt_success").clone();
        cnt.children(".p_body").children("h4").vl(title);
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();

    };
    window.info = function (msg, delay,fnCallback) {
        var cnt = $("#tplPrompt>.prompt_info").clone();
        cnt.children(".p_body").children("h4").vl(title);
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();
    };
    window.error = function ( msg, delay, fnCallback) {
        var cnt = $("#tplPrompt>.prompt_err").clone();
        cnt.children(".p_body").children("h4").vl(title);
        cnt.children(".p_body").children("span").vl(msg);
        var p = new LiberUI.Prompt(cnt);
        p.option("Delay", delay);
        p.update();
        if (ObjHelper.IsFunc(fnCallback)) {
            p.on("disposed", fnCallback);
        }
        return p.show();
    };

    window.log = function (msg) {
        if (console) {
            console.log(msg);
        }
    };

    </script>
</body>
</html>



